package com.cvtt.common;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;


public class NetworkUtil {

	private static NetworkInfo getNetworkInfo(Context context) {
		return ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
	}

	/**
	 * 得到联网类型
	 * 
	 * @param null
	 * @return ConnectivityManager.TYPE_MOBILE 或者 ConnectivityManager.TYPE_WIFI
	 */
	public static int getNetworkType(Context context) {
		return getNetworkInfo(context).getType();
	}

	/**
	 * 得到详细网络类型
	 * 
	 * @param null
	 * @return TelephonyManager.NETWORK_TYPE_EDGE 或 TelephonyManager.NETWORK_TYPE_UMTS 等
	 */
	public static int getNetworkSubtype(Context context) {
		return getNetworkInfo(context).getSubtype();
	}

	/**
	 * 检测网络连接是否可用
	 * 
	 * @param null
	 * @return true 可用; false 不可用
	 */
/*	public static boolean isNetworkAvailable(Context context) {
		// Modified by huah in 2012-11-26
		if (context == null)
			context = UApplication.getApplication().getAppContext();
		NetworkInfo netInfo = getNetworkInfo(context);
		if (netInfo != null) {
			return netInfo.isAvailable();
		}
		return false;
	}*/

	public static boolean isAvailable(Context context) {
		NetworkInfo netInfo = getNetworkInfo(context);
		if (netInfo != null) {
			return netInfo.isAvailable();
		}
		return false;
	}

	
}
